package com.spring.aop.custom;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Objects;

/**
 * @ClassName MyinvocationHandler
 * @Description
 * @Author suncx
 * @Date 2020/8/19 14:59
 * @Version 1.0
 */
public class MyinvocationHandler implements InvocationHandler {
    public Object target;
    public MyinvocationHandler(Object target) {
        super();
        this.target = target;
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("before....");
        Object res = method.invoke(target, args);
        System.out.println("after....");
        return res;
    }

    /**
     * 获取目标对象的代理对象
     * @return
     */
    public Object getProxy() {
        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), target.getClass().getInterfaces(), this);
    }
}
